package com.weactivity.mapper;

import com.weactivity.entity.Reminder;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReminderMapper {

    @Insert("insert into reminder (aid,uid,content,remind_time,create_time) values (#{aid},#{uid},#{content},#{remind_time},NOW());")
    int insertReminder(@Param("aid")int aid, @Param("uid")int uid, @Param("content") String content, @Param("remind_time") LocalDateTime remind_time);

    List<Reminder> searchAll(@Param("id") Long id);

    @Delete("delete from reminder where id = #{id} ;")
    int deleteById(@Param("id") int id);

    @Select("SELECT * FROM reminder WHERE DATE_FORMAT(remind_time, '%Y-%m-%d %H:%i') = DATE_FORMAT(#{now}, '%Y-%m-%d %H:%i')")
    List<Reminder> findNeedtoAlert(@Param("now") LocalDateTime now);
}
